home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 361_01 / query.c < prev    next >
C/C++ Source or Header  |  1991-09-18  |  3KB  |  92 lines

  1.  
  2. /* Query.c --> A Gernal Purpose "Ask Box" w/ Context Sensitive Help
  3.  *
  4.  * Author: J.Ekwall                                     13 September 91
  5.  *
  6.  * Copyrighted to the Public Domain.  Unlimited Distribution Authorized.
  7.  *
  8.  * User Assumes All Risks/Liabilities.
  9.  *
  10.  * Last Update: 13 September 91/EK
  11.  */
  12.  
  13. #include <stdek.h>
  14. #include <gadgets.h>
  15. #include <stdio.h>
  16. #include <keys.h>
  17.  
  18. int AnyCharacter(void)
  19. { /* Create Any Character */
  20.     int c, ch = 0, n = 3, xx, yy;
  21.     char FootPrint[216];
  22.  
  23.  /* Ask 'em */
  24.     Getxy(&xx, &yy);
  25.     MkAskBox(FootPrint, 28, 11, 26, 3, 'L', "[ ASCII Value ]",
  26.        "[ <ESC> to Cancel ]", "Enter Three Digits: ", 0x4E);
  27.  
  28.  /* Catch Response, Build Character & Split */
  29.     while (n && (c = Kbq_read()) != ESC && c != CR)
  30.        if (isdigit(c)) { ch = 10 * ch + c - '0'; n--; DputChr(c, 0x4E); }
  31.     ZapAskBox(FootPrint, 28, 11, 26, 3, 'L'); Gotoxy(xx, yy); ShowCursor(1);
  32.     if (c IS ESC) return 0; else return ch & 0xFF;
  33. }
  34.  
  35. int Query(char *Text, char *TopTitle, int CaseLess, BYTE Color,
  36.    char **Help2Pop)
  37. {
  38.     int c, xx, yy;
  39.     char *tp1, FootPrint[488];
  40.  
  41.  /* Establish Window */
  42.     tp1 = Text; Getxy(&xx, &yy);
  43.     MkAskBox(FootPrint, 5, 10, 60, 3, 'L', TopTitle,
  44.           "[ <Esc> to Cancel ]", Text,  Color);
  45.     while ((c = Kbq_read()) != CR) {
  46.        if (CaseLess) c = toupper(c);
  47.        if (c IS ESC) { *Text = NULL; Text[1] = ESC; break; }
  48.        else if (c IS BS) {
  49.           if (tp1 IS Text) {
  50.              if (!strlen(Text)) continue; tp1 += strlen(Text);  }
  51.           tp1--; c = NULL; }
  52.        else if (c IS F1 && Help2Pop != NULL) { PopHelp(Help2Pop); continue; }
  53.        else if (c IS F2) c = AnyCharacter();
  54.        else if (CaseLess IS -1) { if (!isdigit(c)) continue; }
  55.        else if (CaseLess IS -2 && c IS SPACE) continue;
  56.        else if (!iscntrl(c) && isascii(c));
  57.        else continue;
  58.        if (c && strlen(Text) < 57) *tp1++ = c; *tp1 = NULL;
  59.        DwriteEnd(6, 11, Color, Text, 57);
  60.     }
  61.     ZapAskBox(FootPrint, 5, 10, 60, 3, 'L'); Gotoxy(xx, yy); ShowCursor(1);
  62.     return !(!*Text && Text[1] IS ESC);
  63. }
  64.  
  65. void PopHelp(char **PopHelpPtr)
  66. {
  67.     int i, j, xx, yy, Flag;
  68.     char   **dp, FootPrint[2810];
  69.  
  70.     Getxy(&xx, &yy);
  71.     for (i = 2, dp = PopHelpPtr; *dp; dp++) i++; if (i > 22) i = 22;
  72.     Flag = HideCursor();
  73.     MkAskBox(FootPrint, 5, 2, 60, i, 'L', "", "[ Hit Any Key ]", "", 0x0A);
  74.     HideCursor();
  75.     for (dp = PopHelpPtr, j = 3; *dp; dp++) {
  76.        Dwrite(6, j, 0x0A, *dp);
  77.        if (++j IS 22 || dp[1] IS NULL) {
  78.           if (dp[1] !=  NULL) Dwrite(6, j, 0x0A, "--- More --- ");
  79.           switch (Kbq_read()) {
  80.           case  ESC:  j = EOF; break;
  81.           case PGUP:
  82.              if ((dp -= 18) < PopHelpPtr + 10) dp = PopHelpPtr + 9;
  83.           default:   if (dp[1]  != NULL) dp -= 10;
  84.           }
  85.           if (j IS EOF) break;  j = 3; ClrBox(6, 3, 63, 22, 0x0A);
  86.        }
  87.     }
  88.     ZapAskBox(FootPrint, 5, 2, 60, i, 'L'); Gotoxy(xx, yy);
  89.     if (Flag) ShowCursor(0);
  90. }
  91.  
  92.